#include <xen/serial.h>
#include <asm/io.h>
+/* Config serial port with a string <baud>,DPS,<io-base>,<irq>. */
+static unsigned char opt_com1[30] = OPT_COM1_STR, opt_com2[30] = OPT_COM2_STR;
+string_param("com1", opt_com1);
+string_param("com2", opt_com2);
+
/* Register offsets */
#define RBR 0x00 /* receive buffer */
#define THR 0x00 /* transmit holding */
#define RXBUFSZ 32
#define MASK_RXBUF_IDX(_i) ((_i)&(RXBUFSZ-1))
-typedef struct {
+struct uart {
int baud, data_bits, parity, stop_bits, io_base, irq;
serial_rx_fn rx_lo, rx_hi, rx;
spinlock_t lock;
unsigned char rxbuf[RXBUFSZ];
unsigned int rxbufp, rxbufc;
struct irqaction irqaction;
-} uart_t;
+};
-static uart_t com[2] = {
+static struct uart com[2] = {
{ 0, 0, 0, 0, 0x3f8, 4,
NULL, NULL, NULL,
SPIN_LOCK_UNLOCKED },
#define UART_ENABLED(_u) ((_u)->baud != 0)
#define DISABLE_UART(_u) ((_u)->baud = 0)
-/* Architecture-specific private definitions. */
-#include <asm/serial.h>
-
-/* opt_com[12]: Config serial port with a string <baud>,DPS,<io-base>,<irq>. */
-static unsigned char opt_com1[30] = OPT_COM1_STR, opt_com2[30] = OPT_COM2_STR;
-string_param("com1", opt_com1);
-string_param("com2", opt_com2);
-
/***********************
* PRIVATE FUNCTIONS
*/
-static void uart_rx(uart_t *uart, struct xen_regs *regs)
+static void uart_rx(struct uart *uart, struct xen_regs *regs)
{
unsigned char c;
}
}
-static void serial_interrupt(int irq, void *dev_id, struct xen_regs *regs)
+static void serial_interrupt(
+ int irq, void *dev_id, struct xen_regs *regs)
{
- uart_rx((uart_t *)dev_id, regs);
+ uart_rx((struct uart *)dev_id, regs);
}
-static inline void __serial_putc(uart_t *uart, int handle, unsigned char c)
+static inline void __serial_putc(
+ struct uart *uart, int handle, unsigned char c)
{
unsigned long flags;
int space;
return; \
} while ( 0 )
-static void parse_port_config(char *conf, uart_t *uart)
+static void parse_port_config(char *conf, struct uart *uart)
{
if ( *conf == '\0' )
return;
}
}
-static void uart_config_stage1(uart_t *uart)
+static void uart_config_stage1(struct uart *uart)
{
unsigned char lcr;
outb(FCR_ENABLE | FCR_CLRX | FCR_CLTX | FCR_TRG14, uart->io_base + FCR);
}
-static void uart_config_stage2(uart_t *uart)
+static void uart_config_stage2(struct uart *uart)
{
int rc;
void serial_set_rx_handler(int handle, serial_rx_fn fn)
{
- uart_t *uart = &com[handle & SERHND_IDX];
+ struct uart *uart = &com[handle & SERHND_IDX];
unsigned long flags;
if ( handle == -1 )
void serial_putc(int handle, unsigned char c)
{
- uart_t *uart = &com[handle & SERHND_IDX];
+ struct uart *uart = &com[handle & SERHND_IDX];
if ( handle == -1 )
return;
void serial_puts(int handle, const unsigned char *s)
{
- uart_t *uart = &com[handle & SERHND_IDX];
+ struct uart *uart = &com[handle & SERHND_IDX];
if ( handle == -1 )
return;
unsigned char irq_serial_getc(int handle)
{
- uart_t *uart = &com[handle & SERHND_IDX];
+ struct uart *uart = &com[handle & SERHND_IDX];
unsigned char c;
unsigned char serial_getc(int handle)
{
- uart_t *uart = &com[handle & SERHND_IDX];
+ struct uart *uart = &com[handle & SERHND_IDX];
unsigned char c;
unsigned long flags;
void serial_force_unlock(int handle)
{
- uart_t *uart = &com[handle & SERHND_IDX];
+ struct uart *uart = &com[handle & SERHND_IDX];
if ( handle != -1 )
uart->lock = SPIN_LOCK_UNLOCKED;
}
/* -*- Mode:C; c-basic-offset:4; tab-width:4; indent-tabs-mode:nil -*- */
-/******************************************************************************
- * asm-x86/serial.h
- *
- * Architecture-specific private serial definitions.
- */
#ifndef __ASM_X86_SERIAL_H__
#define __ASM_X86_SERIAL_H__
#define OPT_COM1_STR ""
#define OPT_COM2_STR ""
-static inline int arch_serial_putc(uart_t *uart, unsigned char c)
-{
- int space;
- if ( (space = (inb(uart->io_base + LSR) & LSR_THRE)) )
- outb(c, uart->io_base + THR);
- return space;
-}
+#define arch_serial_putc(_uart, _c) \
+ ( (inb((_uart)->io_base + LSR) & LSR_THRE) ? \
+ (outb((_c), (_uart)->io_base + THR), 1) : 0 )
#endif /* __ASM_X86_SERIAL_H__ */